const stateRefs = {};

const handleSnapshotEvt = (vueInst, evtMsg) => {
	if('click' != evtMsg.type){
		return;
	}
	let domRef = stateRefs.domRef;
	let nodeRef = domRef.getElementByIdKey(evtMsg.id);
	if(null == nodeRef || null == nodeRef.node){
		return;
	}
	vueInst.updateScrapeInfo(nodeRef.node);

};

const foundSnapshotId = (element) => {
	let domRef = stateRefs.domRef;
	let idKey = domRef.getSeqIdKey();
	return element[idKey];

};

const foundSnapshotParentIds = (element) => {
	let idMap = {};
	let domRef = stateRefs.domRef;
	let idKey = domRef.getSeqIdKey();
	let nodeId = element[idKey];
	let nodeRef = domRef.getElementByIdKey(nodeId);
	while(null != nodeRef && 0 != nodeRef.node){
		let node = nodeRef.node;
		let parent = node.parentNode;
		if(null == node.parentNode){
			break
		}
		let parentId = parent[idKey];
		idMap[parentId] = parentId;
		nodeRef = domRef.getElementByIdKey(parentId);
	}
	return idMap;

};

const setupService = (vueInst) => {
	stateRefs.domRef = vueInst.$root.serviceRefs.domRef;

};

export default function(vueInst){
	setupService(vueInst);
	return {
		handleSnapshotEvt,
		foundSnapshotParentIds,
		foundSnapshotId
	};

}